<?php	
	require_once KLEO_LIB_DIR.'core.lib.php';

	class contact extends contactmodel{
	
		/* Call to the model Class */
		function __construct(){
			$this->index();
		}

		function load_form(&$buff){
			if(!isset($_POST['contact'])){
				$this->tpl_load('form.tpl', $cbuff, false);
				$this->compile($cbuff, $cbuff);
				$this->tpl_set("WEB_CONTENT", $cbuff, $cbuff, $buff);
			} else {
				$this->send_contact($_POST['name'],$_POST['email'],$_POST['web'],$_POST['text']);
				$this->tpl_set("WEB_CONTENT", L_EMAIL_SUCCESS, L_EMAIL_SUCCESS, $buff);
				if(!isset($_SESSION['sent'])){
					$_SESSION['sent'] = 1;
				} else {
					if($_SESSION['sent'] > 2){
						die("Bad girl! ¬¬");
					} else {
						$_SESSION['sent'] = $_SESSION['sent']+1;
					}
				}
			}
			$this->tpl_set("BREADCRUMB", '<a href="index.php" title="home">Home</a> » <a href="?module=contact">'.L_CONTACT.'</a>', $buff, $buff);
		}
		function send_contact($name,$email,$web,$text){
			if(!$this->is_email($email)){
				$this->apperror(L_EMAIL_NOT_VALID, "common");
			}
			if(empty($name)){
				$this->apperror(L_EMPTY_NAME, "common");
			}
			$message = L_CONTACT_TEXT_HEAD."Ip: ".$_SERVER['REMOTE_ADDR']."\n ".L_NAME.": ".$name." \n ".L_WEB.": ".$web." \n\n ".$text;
			$this->sendmail($this->get_core_value("admin_email"), L_CONTACT_SUBJECT.$this->get_core_value('web_name'), $message, "text/plain", null, $name.' <'.$email.'>') ;
		}

	}
?> 
